import { Message } from 'element-ui';
import router from '@/router'

const Mutations = {
    setArr(state, arg){
        state.aaa = arg;
    },

    // 全局判读是否登录状态
    isLoginState(state, arg){
        if(state.isLogin !== true){
            Message({
                showClose: true,
                message: arg.msg,
                type: 'error'
            });
            router.push({ path: '/login' })
        }
    },

    cityLocalstorToState(state, arg){
      state.city = arg;
    },

    // 登录成功
    loginSuccess(state, arg){
        Message({
            showClose: true,
            message: arg.msg,
            type: 'success'
        });
        console.log(arg)
        state.globaltoken = arg.token;
        state.globalUserInfo = arg.data;
        state.isLogin = true;
        
        router.push({ path: '/' })
    },

    // 注册成功
    unifySuccess(state, arg){
        Message({
            showClose: true,
            message: arg.msg,
            type: 'success'
        });
    },

    // 统一失败提示
    snackbar(state, arg){
        Message({
            showClose: true,
            message: arg.text,
            type: 'error'
        });
    },

    // 成功提示
    successbar(state, arg){
        Message({
            showClose: true,
            message: arg.text,
            type: 'success'
        });
    },

    // 退出登录
    loginOut(state){
        state.isLogin = false;
        state.globalUserInfo = null;
        state.globaltoken = null;
        Message({
            showClose: true,
            message: "您已退出登录",
            type: 'success'
        });
    },

    // 获取首页职位列表
    getPositionListSuccess(state, arg){
        state.recruitmentMsg = arg.page;
    },

    //  获取招聘会列表
    getjobFairListSuccess(state, arg){
        if(arg.page.rows.map(x=> x.status == '0').includes(true)){
            state.beforeJobFairMessage = arg.page;
        }else {
            state.jobFairMessage = arg.page;
        }
        
    },

    // 招聘大厅人数
    getUserNumList(state, arg){
      console.log(arg)
      if(state.jobFairMessage.rows == undefined) return;
      if(state.jobFairMessage.rows.length == 0) return;
      state.jobFairMessage.rows.map(val=>{
        arg.jobFairId.map(val2=>{
            if(val2 == val.jobFairId){
             val.onlineperson = arg.res[val2][0].userNum;
             val.onlinecompany = arg.res[val2][1].comNum;
            }
            // val[val2]
          })
      })
    },

    // 选择搜索select方式
    changeSearchSelectVal(state, arg){
        state.searchSelectValue = arg;
    },

    // 搜索内容
    changeSearchVal(state, arg){
        state.searchValue = arg;
    },

    // 获取本地存储数据更新额登录状态和个人信息
    loginLocalstorToState(state, arg){
        if(arg.token) state.globaltoken = arg.token;
        if(arg.globalUserInfo) state.globalUserInfo = JSON.parse(arg.globalUserInfo);
        state.isLogin = true;
    },

    //  路由loading
    updateLoadingStatus (state, payload) {
        state.isLoading = payload.isLoading
        console.log('comit',state.isLoading,payload )

    }

}

export default Mutations;
